package com.lock.immersive.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lock.immersive.exception.BusinessException;
import com.lock.immersive.mapper.CouponMapper;
import com.lock.immersive.pojo.domain.Coupon;
import com.lock.immersive.pojo.dto.CouponDto;
import com.lock.immersive.service.CouponService;
import com.lock.immersive.utils.ErrorCode;
import com.lock.immersive.utils.ResponseApi;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author zhao
* @description 针对表【coupon】的数据库操作Service实现
* @createDate 2023-07-05 11:18:46
*/
@Service
public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon>
    implements CouponService {
    @Resource
    public CouponMapper couponMapper;
    @Override
    public ResponseApi<Object> insertCoupon(CouponDto couponDto) {
        Coupon coupon = new Coupon();
        BeanUtils.copyProperties(couponDto, coupon);
        int insert = couponMapper.insert(coupon);
        if(insert>0){
            return ResponseApi.success();
        }else {
            throw new BusinessException(ErrorCode.CREATE_COUPON_ERROR);
        }
    }
}




